package m3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer  {
    public static void main(String[] args) throws IOException, TimeoutException {
        //建立连接
          ConnectionFactory f =  new ConnectionFactory();
          f.setHost("192.168.64.140");//wht6.cn
          f.setUsername("admin");
          f.setPassword("admin");
        Channel c = f.newConnection().createChannel();
        //创建Fanout交换机 命名为：logs
        c.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);//"FANOUT"



        //向交换机发生消息
        while (true){
            System.out.println("输入消息： ");
            String s= new Scanner(System.in).nextLine();
            //对于fanout交换机 第二个参数无效
            c.basicPublish("logs", "", null, s.getBytes());

        }
        //
    }
}
